package com.example.mycblxin;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.example.mycblxin.R;

public class MainActivity extends AppCompatActivity {

    private TextView textViewCounter;
    private int counter = 0; // Initialize the counter value.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textViewCounter = findViewById(R.id.textView_counter);

        Button buttonMinusOne = findViewById(R.id.button_minus_one);
        buttonMinusOne.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                decrement();
            }
        });

        Button buttonReset = findViewById(R.id.button_reset);
        buttonReset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                reset();
            }
        });

        Button buttonPlusOne = findViewById(R.id.button_plus_one);
        buttonPlusOne.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                increment();
            }
        });
    }

    private void increment() {
        ++counter;
        updateDisplay(counter);
    }

    private void decrement() {
        --counter;
        updateDisplay(counter);
    }

    private void reset() {
        counter = 0;
        updateDisplay(counter);
    }

    private void updateDisplay(int count) {
        textViewCounter.setText(String.valueOf(count));
    }
}